package com.algo.proto.server;

import com.algo.proto.DataInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class ProtoServerHandler extends SimpleChannelInboundHandler<DataInfo.AbstractObject> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, DataInfo.AbstractObject msg) throws Exception {
		System.out.println("-----------------------");
		DataInfo.AbstractObject.ObjectType objectType = msg.getObjectType();
//		if (objectType == ObjectType.STUDENT) {
//			DataInfo.Student student = msg.getStudent();
//			System.out.println(student.getName());
//			System.out.println(student.getAge());
//			System.out.println(student.getAddress());
//		}
//		if (objectType == ObjectType.CAR) {
//			DataInfo.Car car = msg.getCar();
//			System.out.println(car.getBrand());
//			System.out.println(car.getPrice());
//		}
//		if (objectType == ObjectType.BALL) {
//			DataInfo.Ball ball = msg.getBall();
//			System.out.println(ball.getCategory());
//			System.out.println(ball.getColor());
//		}
		DataInfo.Student student = msg.getStudent();
		System.out.println(student.getName());
		System.out.println(student.getAge());
		System.out.println(student.getAddress());
		
		DataInfo.Car car = msg.getCar();
		System.out.println(car.getBrand());
		System.out.println(car.getPrice());
		
		DataInfo.Ball ball = msg.getBall();
		System.out.println(ball.getCategory());
		System.out.println(ball.getColor());
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
		cause.printStackTrace();
		ctx.close();
	}

}